/**
 * Copyright (c) 2012 Fujian FUNO Mobile Communication Technology Co., Ltd.
 * All rights reserved by FUNO.
 */
package com.funo.ehealth.util;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/** 
 * xml解析器
 * 
 * @version V1.1
 * @author zhangguangying
 * @date 2012-11-16
 */
public class XmlUtil {
	
	/**
	 * XmlUtil日志记录器
	 */
	private static final Log log = LogFactory.getLog(XmlUtil.class);

	/**
	 * 取得xml报文某个节点的文本
	 * @param xml xml文本
	 * @param element 子元素
	 * @param node 节点
	 * @return String
	 */
	public static String getNodeData(String xml,String node) {
		Document document = null;
		String nodeString = null;
		
		try {
			document = DocumentHelper.parseText(xml);
		} catch (DocumentException e) {
			throw new RuntimeException(StringUtil.handleString("取得xml报文某个节点的文本异常，参数：{xml:{},node:{}}", xml,node),e);
//			LogUtil.error(log, e, "取得xml报文某个节点的文本异常，参数：{xml:{},node:{}}", xml,node);
		}
		List<Element> list = document.selectNodes(node);
		
		if(list != null && list.size() > 0){
			for (Element item : list) {
				nodeString = item.getText();
			}
		}
		
		return nodeString;
	}
	
}
